package com.lanmao.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanmao.blog.entity.Type;
import com.lanmao.blog.mapper.TypeMapper;
import com.lanmao.blog.service.TypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanmao.blog.utils.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lanmao
 * @since 2022-03-13
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {
    @Override
    public List<Type> getAllType() {
        List<Type> types = baseMapper.selectList(null);
        return types;
    }

    @Override
    public Page<Type> pageTypes(Long current, Long size) {
        Page<Type> typePage = new Page<>(current,size);
        //构建条件
        QueryWrapper<Type> wrapper = new QueryWrapper<>();
        //调用mybatis plus分页方法进行查询
        baseMapper.selectPage(typePage,wrapper);
        return typePage;
    }

    @Override
    public List<Type> getTypeByName(String name) {
        QueryWrapper<Type> q = new QueryWrapper<>();
        List<Type> list = baseMapper.selectList(q.like("name", name));
        return list;

    }
    @Override
    public boolean saveType(Type type) {
        int insert = baseMapper.insert(type);
        return insert>0?true:false;
    }
}
